<template>
    <el-row  class="warp-bom" type="flex" justify="center" align="middle">
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span style="line-height: 36px;">登陆</span>
            </div>
            <el-form label-position="right" label-width="80px" :model="loginInfo" :rules="rules" ref="loginInfo">
                <el-form-item label="用户名" prop="username">
                    <el-input v-model="loginInfo.username"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input v-model="loginInfo.password" type="password"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" native-type="submit" @click.native="handleSubmit('loginInfo')">登陆</el-button>
                </el-form-item>
            </el-form>
        </el-card>

    </el-row>
</template>
<style>

</style>
<script>
    import Api from '../api/index'
    export default{
        data(){
            return{
                loginInfo:{
                    username:"",
                    password:""
                },
                rules:{
                    username:[
                        { required: true, message: '请输入用户名', trigger: 'blur' },
                        { min:4, max:12, message: '长度在 4 到 12 个字符', trigger: 'blur' }
                    ],
                    password:[
                        { required: true, message: '请输入密码', trigger: 'blur' },
                        { min:4, max:12, message: '长度在 4 到 12 个字符', trigger: 'blur' }
                    ]
                }
            }
        },
        components:{
        },
        methods:{
            handleSubmit(formName){
                this.$refs[formName].validate((valid)=>{
                    if(valid){//表单验证成功
                        this.$store.dispatch('localLogin',this.loginInfo);
                    }
                })
            }
        }
    }
</script>
